unit Unit3;

interface

uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, ToolWin, Menus, StdCtrls, MPlayer, ShellAPI;

type
    TOdtwarzacz = class(TForm)
    mediaPlayer: TMediaPlayer;
    music_List: TListBox;
    MainMenu: TMainMenu;
    Plik1: TMenuItem;
    Otwrzplik1: TMenuItem;
    Dodajpliki1: TMenuItem;
    OpenD: TOpenDialog;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    Button6: TButton;
    Cshuffle: TCheckBox;
    procedure mediaPlayerNotify(Sender: TObject);
    procedure Play;
    procedure OtworzPliki(OdtworzOdRazu : Boolean);
    procedure Otwrzplik1Click(Sender: TObject);
    procedure Dodajpliki1Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    Procedure LosujUtwory;

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Odtwarzacz: TOdtwarzacz;

implementation

{$R *.dfm}
procedure TOdtwarzacz.Play;
  begin
    mediaPlayer.FileName:= music_List.Items.Strings[music_List.ItemIndex];
    mediaPlayer.Open;
    mediaPlayer.Play;
  end;

procedure TOdtwarzacz.OtworzPliki(OdtworzOdRazu : Boolean);
  var
    i: Integer;
  begin
     if(OpenD.Execute)then
         begin
           if(music_List.Items.Count > 0)then
              music_List.Items.Clear;
           for i:= 0 to OpenD.Files.Count-1 do
              begin
                 music_List.Items.Add(OpenD.Files[i]);
              end;
           if(OdtworzOdRazu)then
          begin
        music_List.ItemIndex:= 0;
      Play;
    end;
  end;
end;

procedure TOdtwarzacz.Otwrzplik1Click(Sender: TObject);
 begin
  OtworzPliki(True);
 end;

procedure TOdtwarzacz.Dodajpliki1Click(Sender: TObject);
 begin
  OtworzPliki(False);
 end;

procedure TOdtwarzacz.mediaPlayerNotify(Sender: TObject);
begin
  if mediaPlayer.NotifyValue = nvSuccessful then
    begin
      if(Cshuffle.checked)then
      begin
        LosujUtwory;
      end
      else
      begin
        if(music_List.ItemIndex = music_List.Items.Count-1)then
          music_List.ItemIndex:= 0
        else
          music_List.ItemIndex:= music_List.ItemIndex+1;
        Play;
      end;
    end;
end;


procedure TOdtwarzacz.Button1Click(Sender: TObject);
 begin
   Play;
 end;

procedure TOdtwarzacz.Button2Click(Sender: TObject);
  begin
    mediaPlayer.Pause;
  end;

procedure TOdtwarzacz.Button3Click(Sender: TObject);
 begin
    mediaplayer.Stop;
 end;

procedure TOdtwarzacz.Button5Click(Sender: TObject);
begin
     music_List.ItemIndex:= music_List.ItemIndex+1;
     Play;
end;
procedure TOdtwarzacz.Button4Click(Sender: TObject);
begin
      music_List.ItemIndex:= music_List.ItemIndex-1;
     Play;
end;

procedure TOdtwarzacz.Button6Click(Sender: TObject);
 begin
   music_list.DeleteSelected;
   music_List.ItemIndex:= music_List.ItemIndex-1;
 end;

Procedure TOdtwarzacz.LosujUtwory;
begin
    Randomize;
      music_list.ItemIndex:= Random(music_list.Items.Count + 1);
      play;
end;

end.
